Skip to content

feat(labs): show a failed turn inline with its reason and Retry (FIX-2550) - #4738

Merged
jhoffner merged 6 commits into
mainfrom
claude/project-thread-uim4cm
Nov 5, 2026
Merged

jhoffner merged 6 commits into
mainfrom
claude/project-thread-uim4cm

Conversation

@jhoffner

@jhoffner jhoffner commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Requested by Jake · project thread

Implements FIX-2550 per its spec, #4725 (merged).

What it does

In the Claude Code-style and Teammates labs, a turn that fails now shows inline. The registry's request-recovery draws it: who failed ("The main session" or the worker's name), the engine's reason, and Retry. Retry appears only on the newest turn, only when the engine will retry that request, and never while a turn is running. A reply the failed turn never finished is marked Incomplete.

  • Each adapter maps the engine's error item to a failed entry and gains retry(sessionId, requestId), which calls the client's request(id).retry() (spec D1).
  • An entry is retryable when its request belongs to the newest turn that drew an entry and its source is one the engine re-enters: http, mcp or scheduled. A record with no source counts as http (spec D2). Each lab pins its RETRYABLE_SOURCES to the engine's PUBLIC_REENTRY_SOURCES in a test.
  • Claude Code-style adds error to the item types its feed reads. It reads the running turn and the retryable turns from one request listing, so a request notice still costs one read.
  • Each lab installs a byte copy of request-recovery.tsx. .fallowrc.json ignores the copies' unused INTERRUPTED_REASON, as it does for the labs' other registry copies.
  • Each fake gains retry, plus failTurn and retries for the screen tests.
  • Each lab README's "what it reads" table gains the row.

Evidence

Each lab has two test files:

  • test/failed-turn.test.tsx covers the adapter cases (built from an error item shaped the way runAction.ts writes it), the line, and the screen on the fake.
  • test/failed-turn-engine.test.ts runs a real engine through createInProcessFetch. A respond that throws once shows its reason through the adapter's feed, and the adapter's retry runs it again as a second request that completes.

Full suites are green: Claude Code-style 27 files / 183 tests, Teammates 28 / 193. Both labs typecheck, and eslint and check-new-dead-code are clean.

Controls, each run red:

Control Claude Code-style Teammates
Drop the "error" branch from the adapter 3 fail 4 fail
Retry on every failed entry 2 fail 1 fails
Drop "error" from the thread's item types real-engine case fails (Teammates reads every type)
Drop the source check internal-source case fails internal-source case fails
Newest turn from the last raw item trailing-item case fails (already per drawn entry)

Notes


Generated by Claude Code

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
flow-state-dev-build-site Ready Ready Preview Nov 5, 2026 5:51pm UTC
3 Skipped Deployments
Project Deployment Actions Updated
flow-state-dev-docs Ignored Ignored Nov 5, 2026 5:51pm UTC
flow-state-dev-kitchen-sink Ignored Ignored Nov 5, 2026 5:51pm UTC
flow-state-dev-ui Ignored Ignored Preview Nov 5, 2026 5:51pm UTC

Request Review

@linear-code

linear-code Bot commented Nov 4, 2026

Copy link
Copy Markdown

FIX-2550

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T17:55:44.372904Z 6f523bb New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

jhoffner commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator Author

Second look + architecture pass (read-only; for the agent that picks this up)

Overall: the approach is sound. Reusing the registry's request-recovery, mapping error items in each adapter, and the real-engine tests with red controls are all good. Findings below, ranked by how much I'd act on them.

1. latest is derived client-side, and the two labs derive it differently (worth fixing)

  • Claude Code-style (entriesOf): newestTurn = items[items.length - 1]?.requestId, the last item of any kind.
  • Teammates (toEntries): the newest turn that drew an entry, deliberately skipping board passes.
  • The server's rule is neither of these. request-recovery.tsx's own header says the server retries only the session's latest failed/interrupted request record, and useSession.resumeLatestRequest bails unless latestRequest.status is one of those.
  • Failure scenarios:
    • Claude Code-style: if a failed turn is followed by an item the lab doesn't draw (empty-text message, suspension tool_output, notice turn), latest goes false and Retry disappears on a retryable turn.
    • Teammates: if a later turn drew nothing, the opposite can happen. Retry shows on a turn the server no longer considers latest, so it 409s or no-ops.
  • Suggestion: make the two labs agree on one definition, and prefer the server's fact where the client already exposes it (latestRequestId is on the client's session type, client/src/types/index.ts:179). latest = entry.requestId === session.latestRequestId is simpler than recomputing it from items. If the adapters don't have the session row at that point, say why in a comment. Add one test per lab for a failed turn followed by an undrawn item.

2. Duplicated mapping logic across the two adapters (refactor opportunity, modest)

The error item → failed entry shape, the failedTurns set, and the incomplete = failedTurns.has(requestId) && status !== "completed" rule are written twice with small drifts: Teammates uses typeof item.message === "string" guards and Claude Code-style doesn't; incomplete suppresses streaming in one and has no equivalent in the other. A third lab will copy it again.

  • Because the labs are isolated by design (each byte-copies registry files), I wouldn't force a shared package for this. But incomplete is the one rule that needs to stay identical. Either note in both adapters that it mirrors the other, or add one fixture test run against both so drift fails loudly.
  • Item 1 is the real reason to touch this. Fix latest once and the rest can stay duplicated.

3. incomplete can flag a finished reply (check)

item.status !== "completed" marks any non-completed assistant message in a failed turn as Incomplete. What does the engine write for a message cut short by error: in_progress, failed, or incomplete? Also, a turn can have a finished reply, then a later tool or step that throws. Confirm that reply carries completed. The tests build the error item "as runAction.ts writes it"; please make sure the assistant-message fixture status comes from the engine too, not hand-written.

4. Smaller notes

  • Thread.tsx: retryOf is declared between the useInterruptKeys comment and its call, so the comment ("On the document, so the keys work wherever focus is") now sits above the wrong line. Move retryOf up.
  • Claude Code-style Entry hardcodes who="The main session". If Threads mode ever shows a failed thread-lead turn, the label is wrong. Fine today, but the adapter could carry it rather than the component.
  • Teammates drawEntry wraps the whole existing loop body in a closure just to detect whether an entry was drawn (entries.length !== drawn). It's correct, but it touches the largest function in the file for one flag. A one-line pushed counter or returning a boolean from the branches would give a smaller diff.
  • Fake retry in both labs resolves the turn by recomputing turn-${line.id}, a convention coupled to failTurn. Fine for test doubles; a shared helper in fake-lab.ts would stop the two strings drifting.
  • .fallowrc.json: per-copy ignores will grow with each lab. Not a blocker; if a third lab installs this component, switch to a glob over **/flow-state/request-recovery.tsx.

Not suggesting

  • Moving the failed-turn adapter into @flow-state-dev/react or client now. Two consumers with different item sets and divergent semantics are not yet a stable abstraction. Revisit after item 1 settles.
  • Any change to request-recovery.tsx itself. It is a byte copy and should stay one.

Items 1 and 3 are the only ones I'd call correctness-relevant; the rest are optional.


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 895241e77a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread labs/claude-code-style/src/adapter.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify / review (FIX-2550)

Verdict: The shape of the change matches the approved spec and FIX-2370 — map engine error items to a failed entry, draw the registry request-recovery line, and expose adapter.retry → request(id).retry(). That is simpler and more correct than a third, lab-local failure markup (which the spec explicitly rejects). I am not approving yet because the two labs disagree on what “newest turn” means, and Claude Code-style can hide Retry in cases Teammates already handles.

What looks right (keep this approach)

  • Thin screen, fat adapter: Retry stays behind LabAdapter.retry; Entry only receives onRetry when latest && !running. Matches D1 and keeps package calls out of components.
  • Registry reuse: Installed request-recovery.tsx copies are byte-identical to packages/ui/registry/components/request-recovery.tsx (verified). Wiring through existing ErrorBody is the intended FIX-2370 path.
  • Tests: Adapter cases + screen tests + one real-engine test per lab; I ran vitest for both labs’ failed-turn* suites (all green).

Where complexity comes from (mostly unavoidable here)

Chunk ~lines Simpler alternative?
request-recovery.tsx ×2 292 Spec says installed as-is; kitchen-sink uses the same vendoring model. Trimming interrupted/Continue UI would fork the registry file (not allowed).
Adapter + Entry + fake changes ×2 ~200 Two independent lab packages — some duplication is expected.
New tests ×2 ~330 See below — engine E2E is the main dedupe candidate.

Main issue — align “newest turn” / latest (D2)

FIX-2550 D2: Retry follows what the person saw as the last turn; Teammates encodes this by tracking the last item that actually drew an entry (so a board pass that writes no line does not steal latest).

Claude Code-style uses newestTurn = items[items.length - 1]?.requestId when marking failed entries. Any later feed item with a different requestId clears latest, even when that item produces no thread entry — so Retry can disappear while the failure line is still the last thing the user cares about. Teammates’ adapter test “keeps Retry on a failed turn a later board pass wrote no entry for” pins the intended behavior; Claude has no analogous test.

Recommendation: Port Teammates’ two-pass newestTurn logic into entriesOf (or extract a tiny shared helper both adapters call). Add the board-pass (or equivalent “invisible tail item”) adapter test on the Claude side.

(I’m less sure how often Claude’s THREAD_ITEMS-filtered feed hits this in production vs Teammates; even so, one PR should not ship two different definitions of latest.)

Smaller simplify suggestions (optional / follow-up)

  1. Duplicate engine integration tests — failed-turn-engine.test.ts is nearly the same in both labs. One copy (e.g. Teammates only) plus shared adapter unit tests would shrink ~60 lines without losing signal; keeping both is defensible for package isolation.
  2. Registry drift — Kitchen Sink has registry-drift.test.ts; labs rely on fallow + manual discipline. A thin drift check per lab (or shared script) would prevent silent skew from the registry — not required for FIX-2550, but it reduces long-term duplication cost.
  3. Full request-recovery install — Continue/Discard paths are unused in these labs (fallow documents that). That weight is the cost of byte-identical install; no change suggested unless ER-4 later splits “failed-only” vs “interrupted” variants.

Performance

Nothing meaningful for lab thread sizes (extra Set over errors, optional trailing map in Teammates).


Happy to re-review after latest is aligned and Claude gains a regression test mirroring Teammates’ board-pass case.

Open in Web View Automation 

Sent by Cursor Automation: Review For Best Approach

Comment thread labs/claude-code-style/src/adapter.ts Resolved
Comment thread labs/teammates/src/adapter.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Snob — already tight. No POC.

Read specs/issues/FIX-2550/SPEC.md, DECISIONS.md, both labs' adapter.ts, Entry.tsx, Claude Code-style Thread.tsx and the TasksPane / ThreadView Entry calls, Teammates Conversation.tsx, both request-recovery.tsx copies, both failed-turn.test.tsx, both failed-turn-engine.test.ts, both fake-lab.ts diffs, and .fallowrc.json. Seventeen files, +810/−18, on 895241e.

A rewrite does not shrink this contract:

  • The two request-recovery.tsx files are the spec's byte-identical install. INTERRUPTED_REASON is unused on the failed line, and .fallowrc.json ignores the file the same way it ignores error.tsx. Cutting the export breaks the copy. One shared component breaks the lab install.
  • Teammates' drawEntry, the length check, and the one .map are D2: a board pass, a joined step, and a suspension_resume add no entry, so they are not the newest turn. Inlining the if-else that was already there drops the function keyword. Claude Code-style uses the last item's requestId because that feed has no silent pass. One helper for both labs would treat a Teammates board pass as the newest turn.
  • retryOf in Thread.tsx is one line so the closure gets a string after requestId !== undefined. Teammates inlines the call because a failed entry's requestId is required.
  • Adapter cases, screen cases, and the real-engine case are the spec's checks, once per lab. The engine files meet at different seams (watchThread / createWiredLab vs watchConversation / createLabAdapter).
  • The task pane and ThreadView already render <Entry> with no onRetry. That is E4.
  • data-incomplete is unread. The visible Incomplete span is E2. Two attributes are not a smaller contract.

Left as recorded: D1 (adapter verb), D2 (newest from items), the registry copies, E1–E5. FIX-2558 and Kitchen Sink stay out of this PR.

Open in Web View Automation 

Sent by Cursor Automation: Code Snob

@jhoffner
jhoffner added this pull request to stack #4752 November 4, 2026 23:24
Base automatically changed from spec/FIX-2550 to main November 4, 2026 23:25
…2550)

Both labs map the engine's error item to a failed entry drawn by the
registry's request-recovery, mark a reply its turn never finished
incomplete, and offer Retry (the client's request(id).retry(), through a
new adapter verb) on the newest turn only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDAAfKeTwqH2bFcZLD
The engine refuses a retry of a request a task or the flow itself started
(source internal/task), so a Retry on such a failed newest turn could only
fail. The failed entry's `latest` becomes `retryable`: the newest turn and
one of the session's recent requests from a source the engine re-enters
(http, mcp, scheduled; a record with no source is http). Both labs pin
their list to the engine's PUBLIC_REENTRY_SOURCES in a test. Claude
Code-style reads the running turn and the retryable turns from one
request listing, so a request notice is still one read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDAAfKeTwqH2bFcZLD
The newest turn was the last raw item's request, so an item that draws no
entry (a retried notice, an empty message) of another turn hid Retry on
the failed line. It is now the request of the last entry drawn, as in
Teammates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NczDiDAAfKeTwqH2bFcZLD
@jhoffner
jhoffner force-pushed the claude/project-thread-uim4cm branch from 20aaee5 to 5f6e8e6 Compare November 4, 2026 23:25
@jhoffner

jhoffner commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Architect: not approving yet. Cursor's changes-requested review (at 8ac665f) is still live. Its main point, that the two labs disagree on what the newest turn is for Retry (D2), looks addressed by 5f6e8e6 and 14ac1f4, but nothing on the PR says so. Reply on that review with what changed and get it re-reviewed or dismissed, and this unblocks.

— FSD Architect

jhoffner commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

This answers Cursor's changes-requested review (5776428981, on 895241e). Its main point was that the two labs disagreed on which turn counts as newest for Retry (D2). That is fixed:

  • Same rule in both labs (5f6e8e6). In Claude Code-style, the newest turn is now the request of the last entry the thread draws, the same as in Teammates. An item that draws nothing (a retried notice, or an empty message) no longer hides Retry. A new adapter case, "keeps Retry on a failed turn a later item that drew nothing came after", fails under the old raw-item rule.
  • Retry only where the engine will retry (14ac1f4). latest is now retryable: the newest turn, and also a request from a source the engine re-enters (http, mcp, scheduled). Both labs pin that list to the engine's PUBLIC_REENTRY_SOURCES.
  • The optional items. Both real-engine tests stay, because each one is the only check that its own lab's adapter is wired to the real routes. A drift check for the labs' registry copies is out of scope here.

Every inline thread is answered and resolved. Codex's latest review, on 5f6e8e6, has no findings, and CI is green. @cursor please re-review.


Generated by Claude Code

…nto claude/project-thread-uim4cm

# Conflicts:
#	labs/teammates/src/components/Entry.tsx
auto-merge was automatically disabled November 5, 2026 17:46

Head branch was pushed to by a user without write access

…-uim4cm

# Conflicts:
#	labs/claude-code-style/src/components/Thread.tsx
#	labs/teammates/README.md

jhoffner commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator Author

Test (1/3) failed on 6f523bb at packages/shift-manager/test/snapshot-subscribe.test.tsx: 2 cases under "the summary's age and R" cannot find shift-coordinator-as-of-refresh.

The failure is not from this PR. The PR does not touch Shift Manager, and the same two cases fail locally on plain main (335b846, after #4747 merged). The break is on main, so there is nothing to fix here. Both lab suites still pass on this branch.


Generated by Claude Code

@jhoffner
jhoffner added this pull request to the merge queue Nov 5, 2026
Merged via the queue into main with commit 24075d7 Nov 5, 2026
17 of 19 checks passed
@jhoffner
jhoffner deleted the claude/project-thread-uim4cm branch November 5, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants